package com.fingard.avatar.website.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fingard.avatar.website.model.bean.PageView;
import com.fingard.avatar.website.model.bean.ResultContext;
import com.fingard.avatar.website.model.dto.IdDto;
import com.fingard.avatar.website.model.dto.PageAddDto;
import com.fingard.avatar.website.model.dto.PageEditDto;
import com.fingard.avatar.website.model.dto.PagePageDto;
import com.fingard.avatar.website.model.po.SysPagePo;
import com.fingard.avatar.website.model.po.SysUserPo;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import com.fingard.avatar.website.service.SysPageService;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 徐一涛
 * @date 2022-05-10
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("api/page")
@Api(tags = "")
public class SysPageController {

    @Autowired
    private final SysPageService sysPageService;

    @ApiOperation("新增")
    @PostMapping("add")
    public ResultContext<Boolean> add(@Validated PageAddDto req) {
        return ResultContext.success(sysPageService.add(req));
    }

    @PostMapping("edit")
    public ResultContext<Boolean> edit(@Validated PageEditDto req) {
        return ResultContext.success(sysPageService.edit(req));
    }

    @PostMapping("delete")
    public ResultContext<Boolean> delete(@Validated IdDto req) {
        return ResultContext.success(sysPageService.delete(req));
    }

    @PostMapping("page")
    public PageView<SysPagePo> page(@Validated PagePageDto req) {
        IPage<SysPagePo> iPage = sysPageService.page(req);
        return PageView.success(iPage);
    }
}
